package luaj;

public class LuaTables extends LuaTable{
    private LuaValue[] array;
    private LuaTable.Slot[] hash;
    public int size() {
        int len = 0;
        // check array part
        int i = 0;
        for (; i < array.length; ++i) {
            if (array[i] != null) {
                len++;
            }
        }

        // check hash part
        for (i -= array.length; i < hash.length; ++i) {
            Slot slot = hash[i];
            while (slot != null) {
                StrongSlot first = slot.first();
                if (first != null) {
                    len++;
                }
                slot = slot.rest();
            }
        }
        return len;
    }
}
